 package client;

 import constants.SkillConstants;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import server.CharacterCardFactory;
 import tools.Pair;
 import tools.Triple;
 import tools.data.output.MaplePacketLittleEndianWriter;






 public class MapleCharacterCards
 {
/*  22 */   private final List<Pair<Integer, Integer>> skills = new ArrayList<>();
/*  23 */   private Map<Integer, CardData> cards = new LinkedHashMap<>();

   public Map<Integer, CardData> getCards() {
/*  26 */     return this.cards;
   }

   public void setCards(Map<Integer, CardData> cads) {
/*  30 */     this.cards = cads;
   }

   public List<Pair<Integer, Integer>> getCardEffects() {
/*  34 */     return this.skills;
   }

   public void calculateEffects() {
/*  38 */     this.skills.clear();
/*  39 */     int deck1amount = 0, deck2amount = 0, deck3amount = 0, reqRank1 = 0, reqRank2 = 0, reqRank3 = 0;
/*  40 */     List<Integer> cardSkillIds1 = new LinkedList<>();
/*  41 */     List<Integer> cardSkillIds2 = new LinkedList<>();
/*  42 */     List<Integer> cardSkillIds3 = new LinkedList<>();
/*  43 */     CharacterCardFactory cardFactory = CharacterCardFactory.getInstance();
/*  44 */     for (Map.Entry<Integer, CardData> cardInfo : this.cards.entrySet()) {
/*  45 */       if (((CardData)cardInfo.getValue()).chrId > 0) {

/*  47 */         Triple<Integer, Integer, Integer> skillData = cardFactory.getCardSkill(((CardData)cardInfo.getValue()).job, ((CardData)cardInfo.getValue()).level);
/*  48 */         if (((Integer)cardInfo.getKey()).intValue() < 4) {
/*  49 */           if (skillData != null) {
/*  50 */             cardSkillIds1.add(skillData.getLeft());
/*  51 */             this.skills.add(new Pair(skillData.getMid(), skillData.getRight()));
           }
/*  53 */           deck1amount++;
/*  54 */           if (reqRank1 == 0 || reqRank1 > ((CardData)cardInfo.getValue()).level)
/*  55 */             reqRank1 = ((CardData)cardInfo.getValue()).level;  continue;
         }
/*  57 */         if (((Integer)cardInfo.getKey()).intValue() > 3 && ((Integer)cardInfo.getKey()).intValue() < 7) {
/*  58 */           if (skillData != null) {
/*  59 */             cardSkillIds2.add(skillData.getLeft());
/*  60 */             this.skills.add(new Pair(skillData.getMid(), skillData.getRight()));
           }
/*  62 */           deck2amount++;
/*  63 */           if (reqRank2 == 0 || reqRank2 > ((CardData)cardInfo.getValue()).level)
/*  64 */             reqRank2 = ((CardData)cardInfo.getValue()).level; 
           continue;
         }
/*  67 */         if (skillData != null) {
/*  68 */           cardSkillIds3.add(skillData.getLeft());
/*  69 */           this.skills.add(new Pair(skillData.getMid(), skillData.getRight()));
         }
/*  71 */         deck3amount++;
/*  72 */         if (reqRank3 == 0 || reqRank3 > ((CardData)cardInfo.getValue()).level) {
/*  73 */           reqRank3 = ((CardData)cardInfo.getValue()).level;
         }
       }
     }


/*  79 */     if (deck1amount == 3 && cardSkillIds1.size() == 3) {
/*  80 */       List<Integer> uid = cardFactory.getUniqueSkills(cardSkillIds1);
/*  81 */       for (Iterator<Integer> iterator = uid.iterator(); iterator.hasNext(); ) { int i = ((Integer)iterator.next()).intValue();
/*  82 */         this.skills.add(new Pair(Integer.valueOf(i), Integer.valueOf(SkillConstants.getCardSkillLevel(reqRank1)))); }

/*  84 */       this.skills.add(new Pair(Integer.valueOf(cardFactory.getRankSkill(reqRank1)), Integer.valueOf(1)));
     }
/*  86 */     if (deck2amount == 3 && cardSkillIds2.size() == 3) {
/*  87 */       List<Integer> uid = cardFactory.getUniqueSkills(cardSkillIds2);
/*  88 */       for (Iterator<Integer> iterator = uid.iterator(); iterator.hasNext(); ) { int i = ((Integer)iterator.next()).intValue();
/*  89 */         this.skills.add(new Pair(Integer.valueOf(i), Integer.valueOf(SkillConstants.getCardSkillLevel(reqRank2)))); }

/*  91 */       this.skills.add(new Pair(Integer.valueOf(cardFactory.getRankSkill(reqRank2)), Integer.valueOf(1)));
     }
/*  93 */     if (deck3amount == 3 && cardSkillIds3.size() == 3) {
/*  94 */       List<Integer> uid = cardFactory.getUniqueSkills(cardSkillIds3);
/*  95 */       for (Iterator<Integer> iterator = uid.iterator(); iterator.hasNext(); ) { int i = ((Integer)iterator.next()).intValue();
/*  96 */         this.skills.add(new Pair(Integer.valueOf(i), Integer.valueOf(SkillConstants.getCardSkillLevel(reqRank3)))); }

/*  98 */       this.skills.add(new Pair(Integer.valueOf(cardFactory.getRankSkill(reqRank3)), Integer.valueOf(1)));
     }
   }

   public void recalcLocalStats(MapleCharacter chr) {
/* 103 */     int pos = -1;
/* 104 */     for (Map.Entry<Integer, CardData> x : this.cards.entrySet()) {
/* 105 */       if (((CardData)x.getValue()).chrId == chr.getId()) {
/* 106 */         pos = ((Integer)x.getKey()).intValue();
         break;
       }
     }
/* 110 */     if (pos != -1) {
/* 111 */       if (!CharacterCardFactory.getInstance().canHaveCard(chr.getLevel(), chr.getJob())) {
/* 112 */         this.cards.remove(Integer.valueOf(pos));
       } else {
/* 114 */         this.cards.put(Integer.valueOf(pos), new CardData(chr.getId(), chr.getLevel(), chr.getJob()));
       }
     }
/* 117 */     calculateEffects();
   }

   public void loadCards(MapleClient c, boolean channelserver) {
/* 121 */     this.cards = CharacterCardFactory.getInstance().loadCharacterCards(c.getAccID(), c.getWorld());
/* 122 */     if (channelserver) {
/* 123 */       calculateEffects();
     }
   }

   public void connectData(MaplePacketLittleEndianWriter mplew) {
/* 128 */     if (this.cards.isEmpty()) {
/* 129 */       mplew.writeZeroBytes(108);
       return;
     }
/* 132 */     int poss = 0;
/* 133 */     for (CardData i : this.cards.values()) {
/* 134 */       poss++;
/* 135 */       if (poss > 9) {
         return;
       }
/* 138 */       mplew.writeInt(i.chrId);
/* 139 */       mplew.writeInt(i.level);
/* 140 */       mplew.writeInt(i.job);
     }
   }
 }


/* Location:              C:\PGX\Server.jar!\client\MapleCharacterCards.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */